//package com.fingard.dsp.bank.directbank.ccb04;
//
//import com.fingard.FGBiz;
//import com.fingard.constant.Format;
//import com.fingard.diagnostics.LogHelper;
//import com.fingard.dsp.bank.directbank.DirectBase;
//import com.fingard.dsp.bank.directbank.ccb04.util.DESUtil;
//import com.fingard.dsp.bank.directbank.ccb04.util.Des3;
//import com.fingard.dsp.bank.directbank.ccb04.util.RSAHelper;
//import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
//import com.fingard.io.FileHelper;
//import com.fingard.net.WebRequest;
//import com.fingard.text.Base64Helper;
//import com.fingard.text.StringHelper;
//import com.fingard.util.DateHelper;
//import com.fingard.util.secret.salary.FieldHiddenUtil;
//import com.fingard.xml.XmlTextReader;
//import com.fingard.xml.XmlTextWriter;
//import com.jxlife.security.SM2Utils;
//import com.jxlife.security.Util;
//import sun.misc.BASE64Decoder;
//import sun.misc.BASE64Encoder;
//
//import java.io.File;
//import java.net.URLEncoder;
//import java.security.*;
//import java.security.interfaces.RSAPrivateKey;
//import java.security.interfaces.RSAPublicKey;
//import java.text.DateFormat;
//import java.text.DecimalFormat;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.regex.Pattern;
//
//
//public class CCB04Base extends DirectBase {
//    private static final String STR_FORMAT = "0000000000";
//    public static DecimalFormat decimalFormat = new DecimalFormat(STR_FORMAT);
//    public static BASE64Encoder base64Encoder = new BASE64Encoder();
//    public static BASE64Decoder base64Decoder = new BASE64Decoder();
//    protected static String strtmpFile = FGBiz.DSPHOME_Parent + File.separator + "config" + File.separator + "portfiles" + File.separator + "CCB04" + File.separator;
//    //    protected static byte[] triDesKeys = new byte[1024];//3desKeys;
//    private static Date _sessionTime = new Date();
//    protected String txCode = "";
//    protected String signature = "";
//    protected String[] tmpSign = new String[]{"", ""};
//    protected String reqSeqID;
//    protected String xmlLength = "";
//    protected String page = "";
//    //<19为系统流水号,资金流水号>
//    protected Map<String, String> CCBS_TxnSrlNos = new HashMap<String, String>();
//
//
//    public CCB04Base() {
//
//    }
//
//    //在密钥传输交换阶段，使用 DES 进行加解密前需要调用以下方法对 DES 的密钥进行转换，即转换后的才是真正的密钥
//    private static byte[] asc2bin(String hexString) throws Exception {
//        //16进制字符串转16进制字符数组
//        //hexString = hexString.Replace("#", "3");
//        byte[] hexbyte = hexString.getBytes();
//        byte[] bitmap = new byte[hexString.length() / 2];
//        for (int i = 0; i < bitmap.length; i++) {
//            hexbyte[i * 2] -= hexbyte[i * 2] > '9' ? 7 : 0;
//            hexbyte[i * 2 + 1] -= hexbyte[i * 2 + 1] > '9' ? 7 : 0;
//            bitmap[i] = (byte) ((hexbyte[i * 2] << 4 & 0xf0) | hexbyte[i * 2 + 1] & 0x0f);
//        }
//
//        return bitmap;
//    }
//
//    public static String md5(String encryString, String Charset) {
//        try {
//            MessageDigest digest = MessageDigest.getInstance("MD5");
//            digest.update(encryString.getBytes(Charset));
//            byte b[] = digest.digest();
//            int i;
//
//            StringBuffer buf = new StringBuffer("");
//            for (int offset = 0; offset < b.length; offset++) {
//                i = b[offset];
//                if (i < 0)
//                    i += 256;
//                if (i < 16)
//                    buf.append("0");
//                buf.append(Integer.toHexString(i));
//            }
//            digest = null;
//            b = null;
//            return buf.toString();
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }
//
//    protected void getBnkToken() throws Exception {
//        //进行签到
//        Calendar c = Calendar.getInstance();
//        c.setTime(_sessionTime);
//        int oldDay = c.get(Calendar.DAY_OF_MONTH);
//
//        Date date = new Date();
//        Calendar c1 = Calendar.getInstance();
//        c1.setTime(date);
//        int nowDay = c1.get(Calendar.DAY_OF_MONTH);
//
//        String chanl_cust_no = bankFront.org;
//        String targetPubKeyPath = "";
//
//        boolean useLocalSecret = getBankConfig().getValueAsBool("useLocalSecret");
//        WriteBankLogLn("是否读取本地密钥(useLocalSecret):" + useLocalSecret);
//        if (useLocalSecret) {
//            String localEncyptKeyPath = bankFront.bkTransFolder + bankFront.org + "_key.txt";
//            String localPubKeyPath = bankFront.bkTransFolder + bankFront.org + "_BnkPubKey.txt";
//            boolean isNotNeedDecrypt = getBankConfig().getValueAsBool("isNotNeedDecrypt");
//            WriteBankLogLn("是否读取本地密钥后不进行解密:" + isNotNeedDecrypt);
//            if (isNotNeedDecrypt) {
//                WriteBankLogLn("已解密本机银行加密key路径:" + localEncyptKeyPath);
//                String encyptKeyPlainText = FileHelper.readFileText(localEncyptKeyPath, getCharset());
//                WriteBankLogLn("已解密银行加密key明文内容为:" + encyptKeyPlainText);
//                bankFront.token = encyptKeyPlainText;
//                targetPubKeyPath = String.format("%1$s%2$s_BnkPubKey.txt", strtmpFile, chanl_cust_no);
//                WriteBankLogLn("已解密银行公钥路径:" + localPubKeyPath);
//                String localPubKeyMsg = FileHelper.readFileText(localPubKeyPath, getCharset());
//                WriteBankLogLn("已解密银行公钥明文内容为:" + localPubKeyMsg);
//
//            } else {
//                String localDecryptKey = getBankConfig().getValueAsString("localDecryptKey");
//                WriteBankLogLn("本机解密国密私钥key值:" + localDecryptKey);
//
//                // 1.银行加密key解密
//                if (StringHelper.isNullOrEmpty(bankFront.token)) {
//
//                    String localEncyptKeyPath1 = bankFront.bkTransFolder;
//                    WriteBankLogLn("------------------------------------------------");
//                    List<String> pubfileNames = new ArrayList<String>();
//                    File file1 = new File(localEncyptKeyPath1);
//                    if (file1.isDirectory()) {
//                        WriteBankLogLn("localEncyptKeyPath1是真实存在的路径");
//                        File[] files = file1.listFiles();
//                        for (int i = 0; i < files.length; i++) {
//                            pubfileNames.add(files[i].getName());
//                        }
//                    }
//                    WriteBankLogLn("localPubKeyPath路径下的所有文件" + pubfileNames.toString());
//                    File file = new File(localEncyptKeyPath);
//                    if (file.isFile()) {
//                        WriteBankLogLn(localEncyptKeyPath + "是一个文件");
//                    }
//                    WriteBankLogLn("------------------------------------------------");
//                    WriteBankLogLn("本机待解密银行加密key路径:" + localEncyptKeyPath);
//                    String localEncyptKeyMsg = FileHelper.readFileText(localEncyptKeyPath, getCharset());
//                    WriteBankLogLn("本机待解密银行加密key内容:" + localEncyptKeyMsg);
//                    String encyptKeyPlainText = base64Encoder.encode(SM2Utils.decrypt(Util.hexToByte(localDecryptKey), Util.hexToByte(localEncyptKeyMsg)));
//                    WriteBankLogLn("使用国密私钥解密后银行加密key明文内容为:" + encyptKeyPlainText);
//                    bankFront.token = encyptKeyPlainText;
//                }
//
//                // 2.银行公钥解密
//                targetPubKeyPath = String.format("%1$s%2$s_BnkPubKey.txt", strtmpFile, chanl_cust_no);
//                File file = new File(targetPubKeyPath);
//                if (!file.exists()) {
//
//                    String localPubKeyPath1 = bankFront.bkTransFolder;
//                    WriteBankLogLn("------------------------------------------------");
//                    List<String> prifileNames = new ArrayList<String>();
//                    File file2 = new File(localPubKeyPath1);
//                    if (file2.isDirectory()) {
//                        WriteBankLogLn("localPubKeyPath1是真实存在的路径");
//                        File[] files = file2.listFiles();
//                        for (int i = 0; i < files.length; i++) {
//                            prifileNames.add(files[i].getName());
//                        }
//                    }
//                    WriteBankLogLn("localPubKeyPath1路径下的所有文件" + prifileNames.toString());
//                    File file3 = new File(localPubKeyPath);
//                    if (file3.isFile()) {
//                        WriteBankLogLn(localPubKeyPath + "是一个文件");
//                    }
//                    WriteBankLogLn("------------------------------------------------");
//                    WriteBankLogLn("本机待解密银行公钥路径:" + localPubKeyPath);
//                    String localPubKeyMsg = FileHelper.readFileText(localPubKeyPath, getCharset());
//                    WriteBankLogLn("本机待解密银行公钥内容:" + localPubKeyMsg);
//                    String bankPubKeyPlainText = base64Encoder.encode(SM2Utils.decrypt(Util.hexToByte(localDecryptKey), Util.hexToByte(localPubKeyMsg)));
//                    WriteBankLogLn("使用国密私钥解密后银行公钥明文内容为:" + bankPubKeyPlainText);
//                    WriteBankLogLn("本机解密后银行公钥保存路径:" + targetPubKeyPath);
//                    FileHelper.writeFile(targetPubKeyPath, bankPubKeyPlainText, getCharset());
//                    WriteBankLogLn("本机解密后银行公钥保存本机成功...");
//                }
//            }
//        } else {
//            byte[] keys = new byte[40];
//            String sKey = "";
//            sKey = getDESKeys();
//            keys = asc2bin(sKey);
//            byte[] bankPubKeys = new byte[800];//银行rsa公钥
//            byte[] bnkReturn = new byte[1024];
//            byte[] tmpKeys = new byte[1024];
//            String strErrorMsg = "";
//            //下载密钥
//            // 记得删除 模拟下载成功3des密钥
//       /* String abc = "UhR0lzHYxPRAn5FPqIAwwA==";
//        triDesKeys = DESDecrypt(abc, keys);*/
//            try {
////            if (triDesKeys == null || triDesKeys.length == 1024) {
//                //多客户共用同一个dsp的情况，防止3des密钥混乱的问题，把密钥存放在token中
//                if (StringHelper.isNullOrEmpty(bankFront.token)) {
//                    String[] ret = downloadKeys("des");
//                    if (ret[0].length() == 0) {
//                        byte[] tmp1 = new byte[1024];
//                        byte[] tmpBytes = base64Decoder.decodeBuffer(ret[1]);
//                        byte[] responseCode = new byte[6];
//                        //byte[] str_tmpBKRet = new byte[1024];
//                        String strRetCode = "";
//
//                        tmp1 = new byte[tmpBytes.length - 6];
//                        //获取前面6个相应码
//                        System.arraycopy(tmpBytes, 0, responseCode, 0, 6);
//                        strRetCode = new String(responseCode);
//                        System.arraycopy(tmpBytes, 6, tmp1, 0, tmpBytes.length - 6);
//                        if (strRetCode.equals("000000")) {
//                            tmpKeys = tmp1;
//                            byte[] keyByteArr = DESUtil.desDecrypt(tmpKeys, keys);
//                            this.WriteBankLogLn("下载银行3des密钥成功:" + new String(keyByteArr));
//                            bankFront.token = Base64Helper.encode(keyByteArr);
//                            this.WriteBankLogLn("Base64加密后的银行3des密钥值:" + bankFront.token);
//                        } else {
//                            strErrorMsg = new String(tmp1);
//                            this.WriteBankLogLn("下载银行3des密钥失败:" + strErrorMsg);
//                        }
//                    } else {
//                        this.WriteBankLogLn("下载银行3des密钥失败");
//                    }
//                }
//                //下载银行公钥
//                targetPubKeyPath = String.format("%1$s%2$s_BnkPubKey.txt", strtmpFile, chanl_cust_no);
//                File file = new File(targetPubKeyPath);
//                if (!file.exists()) {
//                    String[] ret = downloadKeys("pub");
//                    if (ret[0].length() == 0) {
//                        byte[] tmp1 = new byte[1024];
//
//                        byte[] tmpBytes = base64Decoder.decodeBuffer(ret[1]);
//                        byte[] responseCode = new byte[6];
//                        //byte[] str_tmpBKRet = new byte[1024];
//                        String strRetCode = "";
//
//                        tmp1 = new byte[tmpBytes.length - 6];
//                        //获取前面6个相应码
//                        System.arraycopy(tmpBytes, 0, responseCode, 0, 6);
//                        strRetCode = new String(responseCode);
//                        System.arraycopy(tmpBytes, 6, tmp1, 0, tmpBytes.length - 6);
//                        if (strRetCode.equals("000000")) {
//                            this.WriteBankLogLn("下载银行pub密钥成功" + tmp1);
//                            bnkReturn = tmp1;
//                            bankPubKeys = DESUtil.desDecrypt(bnkReturn, keys);
//                            //本身取到的公钥是java版本的不需要转换
//                            this.WriteBankLogLn("bankPubKeys值:" + bankPubKeys);
//                            String pubKeys = base64Encoder.encode(bankPubKeys);
//                            FileHelper.writeFile(targetPubKeyPath, pubKeys, getCharset());
//                        } else {
//                            strErrorMsg = new String(tmp1);
//                            this.WriteBankLogLn("下载银行pub密钥失败:" + strErrorMsg);
//                        }
//                    } else {
//                        this.WriteBankLogLn("下载银行公钥失败");
//                    }
//                }
//
//            } catch (Exception e) {
//                this.WriteBankLogLn("下载银行密钥失败" + e.getMessage());
//            }
//        }
//
//        if (StringHelper.hasAnyChar(bankFront.token) && new File(targetPubKeyPath).exists()) {
//            if (bankFront.loginFlag.equals("false") || "".equals(bankFront.loginFlag) || oldDay != nowDay) {
//                if (getBankConfig().getValueAsBool("needLogin")) {
//                    WriteBankLogLn("当前未登录前置，现在进行登录");
//                    login();
//                }
//            }
//        }
//        _sessionTime = new Date();
//    }
//
//    //获取des密码
//    private String getDESKeys() {
//        String chanl_cust_no = bankFront.org;//电子合约客户号
//        //取十位客户号
//        if (chanl_cust_no.length() > 10) {
//            int len = chanl_cust_no.length();
//            chanl_cust_no = chanl_cust_no.substring(len - 10);
//        } else {
//            chanl_cust_no = decimalFormat.format(chanl_cust_no);
//        }
//        return chanl_cust_no + Format.Date8Format.format(new Date()).substring(2);//key码为客户号10位+当前日期171107
//    }
//
//    //下载企业密钥
//    public String[] downloadKeys(String keysType) {
//        String[] retStr = new String[]{"", ""};
//        //byte[] tmp1 = new byte[1024];
//        try {
//            String chanl_cust_no = bankFront.org;//电子合约客户号
//
//            WebRequest tmpWebRequest = new WebRequest("http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/KeyTransfer");
//            WriteBankLogLn("下载银行密钥的地址:http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/KeyTransfer");
//            tmpWebRequest.setConnectTimeout(60000);
//            tmpWebRequest.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//            tmpWebRequest.setRequestProperty("connection", "Close");
//            tmpWebRequest.setBankFront(bankFront);
//            String charsetName = getCharset();
//            StringBuilder postData = new StringBuilder();
//            postData.append("chanl_cust_no=" + chanl_cust_no);
//            postData.append("&type=" + keysType);
//            byte[] str_tmpToWriteBytes = postData.toString().getBytes(charsetName);
//            WriteBankLogLn("发送银行下载的数据" + postData.toString());
//            retStr = tmpWebRequest.upload(str_tmpToWriteBytes, charsetName);
//            WriteBankLogLn("下载密钥时银行返回数据" + retStr[1]);
//        } catch (Exception e) {
//            this.WriteBankLogLn("下载银行密钥失败:" + e.getMessage());
//        }
//        return retStr;
//    }
//
//    protected boolean login() {
//        try {
//            int tmpMaxFailCount = getBankConfig().getValueAsInt("maxLoginFail");
//            if (bankFront.loginFailCount >= tmpMaxFailCount) {
//                WriteBankLogLn("登录失败次数" + bankFront.loginFailCount + "已达到上限，不再进行登录");
//                return false;
//            }
//            Date date = new Date();
//            bankFront.lastLoginTime = date;
//            bankFront.loginFlag = "false";
//            txCode = "P1OPME001";
//            XmlTextWriter xmlWriterWithoutCDATA = new XmlTextWriter();//发银行报文的XML对象
//            //写入通用的头部节点
//            writeCommonHeaderWithoutCDATA(xmlWriterWithoutCDATA);
//            xmlWriterWithoutCDATA.writeEndDocument();
//            int n = xmlWriterWithoutCDATA.toXmlString().length();
//            xmlLength = decimalFormat.format(n);
//            XmlTextWriter xmlWriter = new XmlTextWriter();
//            writeCommonHeader(xmlWriter);
//            xmlWriter.writeEndDocument();
//
//            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//            /*//模拟登录成功
//            bankFront.loginFlag = "true";*/
//            if (tmpStrRet[0].length() == 0) {
//                StringBuilder sbMsg = new StringBuilder();
//                XmlTextReader xld_tmpBKRet = loadBankRespXmlReader(tmpStrRet[1], sbMsg);
//                RetAtsBase retAtsBase = new RetAtsBase();
//                retAtsBase.retHeader = reqHeader;
//                retAtsBase.retXmlWriter = new XmlTextWriter();
//                if (IsResultInvlid(tmpStrRet[1], xld_tmpBKRet, true, retAtsBase)) {
//                    bankFront.loginFailCount = 0;
//                    bankFront.loginFlag = "true";
//                    this.WriteBankLogLn("=================签到成功==================\r\n");
//                    return true;
//                } else {
//                    bankFront.loginFailCount = bankFront.loginFailCount + 1;
//                    this.WriteBankLogLn("DSP发起签到失败，请检查报文格式以及与银行的通讯是否正常！");
//                    this.WriteBankLogLn("====================签到失败==================");
//                }
//            } else {
//                WriteBankLogLn("登录失败：" + tmpStrRet[1]);
//            }
//        } catch (Exception e) {
//            WriteBankLogLn("登录异常：" + LogHelper.getStackTrace(e));
//            e.printStackTrace();
//        }
//        return false;
//    }
//
//    protected String getQryTransID() {
//        Date tmpDateNow = new Date();
//        return Format.Time12Format.format(tmpDateNow);
//    }
//
//    protected String getCharset() {
//        return getBankConfig().getCharset("GBK");
//    }
//
//    protected void writeCommonHeader(XmlTextWriter xmlWriter) throws Exception {
//        if (StringHelper.isNullOrEmpty(txCode)) {
//            throw new Exception("未赋值txCode");
//        }
//        Date date = new Date();
//        //写入通用的头部节点
//        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//        xmlWriter.writeStartElement("Transaction");
//        xmlWriter.writeStartElement("Transaction_Header");
//        xmlWriter.writeElementCDATA("SYS_TX_CODE", txCode);
//        xmlWriter.writeElementCDATA("SYS_MSG_LEN", String.valueOf(xmlLength));// 存放报文体的长度数据
//        xmlWriter.writeElementCDATA("SYS_REQ_TIME", Format.Time6Format.format(date));
//        xmlWriter.writeElementCDATA("SYS_TX_VRSN", "01");//服务版本号
//        xmlWriter.writeElementCDATA("TXN_DT", Format.Date8Format.format(date));
//        xmlWriter.writeElementCDATA("TXN_TM", Format.Time6Format.format(date));
//        xmlWriter.writeElementCDATA("TXN_STFF_ID", bankFront.operator);//交易人员编号 必填?
//        xmlWriter.writeElementCDATA("MULTI_TENANCY_ID", "CN000");
//        xmlWriter.writeElementCDATA("LNG_ID", "zh-cn");
//        xmlWriter.writeElementCDATA("REC_IN_PAGE", getBankConfig().getValueAsString("EachPageNum", "100"));
//        xmlWriter.writeElementCDATA("PAGE_JUMP", page);
//        xmlWriter.writeElementCDATA("STS_TRACE_ID", "");//状态跟踪号
//        xmlWriter.writeElementCDATA("CHNL_CUST_NO", bankFront.org);//电子银行合约编号
//        xmlWriter.writeElementCDATA("IttParty_Jrnl_No", reqHeader.transSeqID); //发起方流水号
//        xmlWriter.writeElementCDATA("Txn_Itt_IP_Adr", getBankConfig().getValueAsString("IpAddress"));
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("Transaction_Body");
//    }
//
//    protected void writeCommonHeaderWithoutCDATA(XmlTextWriter xmlWriter) throws Exception {
//        if (StringHelper.isNullOrEmpty(txCode)) {
//            throw new Exception("未赋值txCode");
//        }
//        Date date = new Date();
//        if (getBankConfig().getValueAsBool("useConigureTime")) {
//            String configureTime = getBankConfig().getValueAsString("configureTime");
//            if (StringHelper.hasAnyChar(configureTime)) {
//                date = Format.Date8Format.parse(configureTime);
//            }
//        }
//        //写入通用的头部节点
//        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//        xmlWriter.writeStartElement("Transaction");
//        xmlWriter.writeStartElement("Transaction_Header");
//        xmlWriter.writeElementString("SYS_TX_CODE", txCode);
//        xmlWriter.writeElementString("SYS_MSG_LEN", "", true);// 存放报文体的长度数据
//        xmlWriter.writeElementString("SYS_REQ_TIME", Format.Time6Format.format(date));
//        xmlWriter.writeElementString("SYS_TX_VRSN", "01");//服务版本号
//        xmlWriter.writeElementString("TXN_DT", Format.Date8Format.format(date));
//        xmlWriter.writeElementString("TXN_TM", Format.Time6Format.format(date));
//        xmlWriter.writeElementString("TXN_STFF_ID", bankFront.operator, true);//交易人员编号 必填?
//        xmlWriter.writeElementString("MULTI_TENANCY_ID", "CN000");
//        xmlWriter.writeElementString("LNG_ID", "zh-cn");
//        xmlWriter.writeElementString("REC_IN_PAGE", getBankConfig().getValueAsString("EachPageNum"));
//        xmlWriter.writeElementString("PAGE_JUMP", page, true);
//        xmlWriter.writeElementString("STS_TRACE_ID", "", true);//状态跟踪号
//        xmlWriter.writeElementString("CHNL_CUST_NO", bankFront.org);//电子银行合约编号
//        xmlWriter.writeElementString("IttParty_Jrnl_No", reqHeader.transSeqID); //发起方流水号
//        xmlWriter.writeElementString("Txn_Itt_IP_Adr", getBankConfig().getValueAsString("IpAddress"));
//        xmlWriter.writeEndElement();
//        xmlWriter.writeStartElement("Transaction_Body");
//    }
//
//    //通用域引用范围信息
//    protected void writeComEntityWithoutCDATA(XmlTextWriter xmlWriterWithoutCDATA) {
//        xmlWriterWithoutCDATA.writeElementString("SChl_No", "000000000000000");
//        xmlWriterWithoutCDATA.writeElementString("FwCtl_Node_ID", "000000000000000");
//        xmlWriterWithoutCDATA.writeElementString("IttParty_Bsn_Dt", "", true);
//        xmlWriterWithoutCDATA.writeElementString("Grp_ID", "", true);
//        xmlWriterWithoutCDATA.writeElementString("Cst_ID", "", true);
//        xmlWriterWithoutCDATA.writeElementString("Prim_AR_No", "", true);
//        xmlWriterWithoutCDATA.writeElementString("Root_Node_PdAr_ID", "", true);
//        if (reqHeader.transType.equals("7506") || reqHeader.transType.equals("7515") || reqHeader.transType.equals("7516")) {
//            xmlWriterWithoutCDATA.writeElementString("PdAr_ID", getBankConfig().getValueAsString("queryNo"));//产品合约编号
//        } else if (reqHeader.transType.equals("1908")) {
//            xmlWriterWithoutCDATA.writeElementCDATA("PdAr_ID", getBankConfig().getValueAsString("payNo"));//产品合约编号
//        } else {
//            xmlWriterWithoutCDATA.writeElementCDATA("PdAr_ID", getBankConfig().getValueAsString("default"));
//        }
//        xmlWriterWithoutCDATA.writeElementString("SvM24Hr_Ind", "0");
//        xmlWriterWithoutCDATA.writeElementString("Tmzon_ECD", "08");
//        xmlWriterWithoutCDATA.writeElementString("Rqs_Upload_File_Nm", "", true);
//        xmlWriterWithoutCDATA.writeElementString("Cmpt_Ent_ID", "0000CN000");
//        xmlWriterWithoutCDATA.writeElementString("WF_BIZ_ID", "", true);
//        xmlWriterWithoutCDATA.writeElementString("WF_MNPLT_TP", "", true);
//        xmlWriterWithoutCDATA.writeElementString("WF_FCN_ID", "", true);
//        xmlWriterWithoutCDATA.writeElementString("CCstTr_ID", getBankConfig().getValueAsString("treeId"), true);
//        xmlWriterWithoutCDATA.writeElementString("CCstTrNdID", getBankConfig().getValueAsString("treeNdId"), true);
//    }
//
//    protected void writeComEntity(XmlTextWriter xmlWriter) {
//        xmlWriter.writeElementCDATA("SChl_No", "000000000000000");//子渠道号
//        xmlWriter.writeElementCDATA("FwCtl_Node_ID", "000000000000000");//流控节点编号
//        xmlWriter.writeElementCDATA("IttParty_Bsn_Dt", "");//发起方业务日期
//        xmlWriter.writeElementCDATA("Grp_ID", "");//集团编号
//        xmlWriter.writeElementCDATA("Cst_ID", "");//客户编号
//        xmlWriter.writeElementCDATA("Prim_AR_No", "");//主合约号
//        xmlWriter.writeElementCDATA("Root_Node_PdAr_ID", "");//根节点产品合约编号
//        if (reqHeader.transType.equals("7506") || reqHeader.transType.equals("7515") || reqHeader.transType.equals("7516")) {
//            xmlWriter.writeElementCDATA("PdAr_ID", getBankConfig().getValueAsString("queryNo"));//产品合约编号
//        } else if (reqHeader.transType.equals("1908")) {
//            xmlWriter.writeElementCDATA("PdAr_ID", getBankConfig().getValueAsString("payNo"));//产品合约编号
//        } else {
//            xmlWriter.writeElementCDATA("PdAr_ID", getBankConfig().getValueAsString("default"));
//        }
//        xmlWriter.writeElementCDATA("SvM24Hr_Ind", "0");
//        xmlWriter.writeElementCDATA("Tmzon_ECD", "08");//时区编码
//        xmlWriter.writeElementCDATA("Rqs_Upload_File_Nm", "");
//        xmlWriter.writeElementCDATA("Cmpt_Ent_ID", "0000CN000");//组件实体编
//        xmlWriter.writeElementCDATA("WF_BIZ_ID", "");
//        xmlWriter.writeElementCDATA("WF_MNPLT_TP", "");
//        xmlWriter.writeElementCDATA("WF_FCN_ID", "");
//        xmlWriter.writeElementCDATA("CCstTr_ID", getBankConfig().getValueAsString("treeId"));//现金客户树编号
//        xmlWriter.writeElementCDATA("CCstTrNdID", getBankConfig().getValueAsString("treeNdId"));//现金客户树节点编号
//    }
//
//
//    //通用电票域引用
//    protected void writeElecBillComEntityWithoutCDATA(XmlTextWriter xmlWriterWithoutCDATA, String reqSeqID, String bankCode, int startNum) {
//        xmlWriterWithoutCDATA.writeStartElement("ECDS_REQ_INFO");
//        xmlWriterWithoutCDATA.writeElementString("BkOthSeqNo", reqSeqID);//发送方流水号
//        xmlWriterWithoutCDATA.writeElementString("BkHvpBrchNo", bankCode);//原电票交易机构号  账户开户机构
//        xmlWriterWithoutCDATA.writeElementString("__BEGIN_REC", startNum + "");//开始记录数
//        xmlWriterWithoutCDATA.writeElementString("__MAX_REC", getBankConfig().getValueAsString("EachPageNum"));//一次查询最大记录数
//        xmlWriterWithoutCDATA.writeEndElement();
//    }
//
//
//    //通用电票域引用
//    protected void writeElecBillComEntity(XmlTextWriter xmlWriter, String reqSeqID, String bankCode, int startNum) {
//        xmlWriter.writeStartElement("ECDS_REQ_INFO");
//        xmlWriter.writeElementCDATA("BkOthSeqNo", reqSeqID);//发送方流水号
//        xmlWriter.writeElementCDATA("BkHvpBrchNo", bankCode);//原电票交易机构号  账户开户机构
//        xmlWriter.writeElementCDATA("__BEGIN_REC", startNum + "");//开始记录数
//        xmlWriter.writeElementCDATA("__MAX_REC", getBankConfig().getValueAsString("EachPageNum"));//一次查询最大记录数
//        xmlWriter.writeEndElement();
//    }
//
//
//    protected String[] sendToBank(String p_reqStr) throws Exception {
//        String[] retStr = new String[]{"", ""};
//        String chanl_cust_no = bankFront.org;//电子合约客户号
//
//        String urlPath = this.bankFront.getUrl("interlink");
//        if (StringHelper.isNullOrEmpty(urlPath)) {
//            urlPath = "http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/interlink";
//        }
//        WriteBankLogLn("1.提交银行的地址：" + urlPath);
//        if (isNeedHiddleField) {
//            WriteBankLogStep2(FieldHiddenUtil.amountHiddle(p_reqStr, new String[]{"TAmt"}));
//        } else {
//            WriteBankLogStep2(p_reqStr);
//        }
//        WebRequest tmpWebRequest = new WebRequest(urlPath);
//        tmpWebRequest.setConnectTimeout(60000);
//        tmpWebRequest.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//        tmpWebRequest.setRequestProperty("connection", "Close");
//        tmpWebRequest.setBankFront(this.bankFront);
//        String charsetName = getCharset();
//        byte[] tmpToWriteBytes = p_reqStr.getBytes(charsetName);
//        //3DES字节加密
////        if (triDesKeys.length == 1024) {
//        if (StringHelper.isNullOrEmpty(bankFront.token)) {
//            WriteBankLogLn("下载银行公钥失败");
//        }
////        byte[] des = Des3.encryptMode(triDesKeys, tmpToWriteBytes);
//        byte[] des = Des3.encryptMode(Base64Helper.decode(bankFront.token), tmpToWriteBytes);
//        String str_3DES = base64Encoder.encode(des);
//        //用MD5withRSA签名
//        //去密钥文件内容
//        String priKey = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_prikey.txt", getCharset());
//        WriteBankLogLn("prikey内容:" + priKey);
//        //boolean tmpIsException = false;
//        String str_MD5withRSA = "";
//        //java的Signature API 的私钥签名
//        if (!"".equals(priKey) && priKey != null) {
//            str_MD5withRSA = RSAHelper.sign(new String(tmpToWriteBytes, getCharset()), priKey, getCharset());
//        }
//        WriteBankLogLn("str_MD5withRSA内容:" + str_MD5withRSA);
//        StringBuilder stringBuilder = new StringBuilder();
//        boolean enableSalaryDecrypt = getBankConfig().getValueAsBool("enableSalaryDecrypt");
//        stringBuilder.append("chanl_cust_no=" + URLEncoder.encode(chanl_cust_no, getCharset()));
//        stringBuilder.append("&xml=" + URLEncoder.encode(str_3DES, getCharset()));
//        stringBuilder.append("&signature=" + URLEncoder.encode(str_MD5withRSA, getCharset()));
//        if (!enableSalaryDecrypt) {
//            WriteBankLogLn("3:加密后发送银行的报文" + stringBuilder.toString());
//        }
//        byte[] inputBytes = stringBuilder.toString().getBytes(charsetName);
//        String pubkey = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_pubkey.txt", getCharset());
//        WriteBankLogLn("pubkey内容:" + pubkey);
//        WriteBankLogLn("发送银行数据验签结果:" + RSAHelper.verifySignData(p_reqStr, str_MD5withRSA, pubkey, getCharset()));
//        retStr = tmpWebRequest.upload(inputBytes, charsetName);
////        if(enableSalaryDecrypt) {
////            WriteBankLogLn("4:银行返回的报文" +FieldHiddenUtil.amountHiddle(retStr[1],new String[]{"TAmt","Scss_Amt","Fail_Amt","SRP_TxnAmt"}));
////        }else {
////            WriteBankLogLn("4:银行返回的报文" + retStr[1]);//new String(base64Decoder.decodeBuffer(retStr[1]))
////        }
//        if (!isNeedHiddleField) {
//            if (enableSalaryDecrypt) {
//                WriteBankLogLn("4:银行返回的报文" + FieldHiddenUtil.amountHiddle(retStr[1], new String[]{"TAmt", "Scss_Amt", "Fail_Amt", "SRP_TxnAmt"}));
//            } else {
//                WriteBankLogLn("4:银行返回的报文" + retStr[1]);//new String(base64Decoder.decodeBuffer(retStr[1]))
//            }
////            WriteBankLogLn("4:银行返回的报文" + retStr[1]);
//        }
//        return retStr;
//    }
//
//    //下载电子回单    http://ip:port/interlink/DownloadFi
//    protected String[] download(String p_reqStr) throws Exception {
//        String[] retStr = new String[]{"", ""};
//        //byte[] tmp1 = new byte[1024];
//        try {
//            WebRequest tmpWebRequest = new WebRequest("http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/DownloadFile");
//            WriteBankLogLn("上传地址:http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/DownloadFile");
//            tmpWebRequest.setConnectTimeout(60000);
//            tmpWebRequest.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//            tmpWebRequest.setRequestProperty("connection", "Close");
//            tmpWebRequest.setBankFront(bankFront);
//            String charsetName = getCharset();
//            byte[] str_tmpToWriteBytes = p_reqStr.getBytes(charsetName);
//            WriteBankLogLn("发送银行的数据" + p_reqStr);
//            retStr = tmpWebRequest.upload(str_tmpToWriteBytes, charsetName);
//
//            WriteBankLogLn("下载银行返回数据" + retStr[1]);
//        } catch (Exception e) {
//            this.WriteBankLogLn("HttpPost文件失败:" + e.getMessage());
//            FGBiz.logTrace.exception(this.getLogCode(), e);
//        }
//
//        return retStr;
//
//    }
//
//    //解析银行返回
//    protected boolean IsResultInvlid(String P_BNKReturn, XmlTextReader P_BKRet, boolean isLogin, RetAtsBase retAtsBase) throws Exception {
//        byte[] tmpBNKReturnBytes = null;
//        try {
//            if (P_BNKReturn.length() > 0 && !"".equals(P_BNKReturn)) {
//                //得到银行返回的数字签名Md5_byte和报文密文DES_byte
//                //HTTP 服务方返回时是返回一个字节流 byte[]，因此需要约定 byte[]的数据格式。
//                //返回的 byte[]的格式：数字签名的长度(固定长度 10 个字节) +数字签名数据+加密后的数据。解密时应先根据前 10 位算出数字签名的长度，然后再截取数字签名及报文密文。
//
//                byte[] data = base64Decoder.decodeBuffer(P_BNKReturn);
//                byte[] len_byte = new byte[10];
//                System.arraycopy(data, 0, len_byte, 0, 10);
//
//                int MD5_len = Integer.valueOf(new String(len_byte));
//                byte[] Md5_byte = new byte[MD5_len];
//                System.arraycopy(data, 10, Md5_byte, 0, MD5_len);
//                byte[] DES_byte = new byte[data.length - 10 - MD5_len];
//                System.arraycopy(data, MD5_len + 10, DES_byte, 0, data.length - 10 - MD5_len);
//
//                //region 3DES字节解密
//
////                byte[] p_Key = triDesKeys;
//                byte[] p_Key = Base64Helper.decode(bankFront.token);
//                tmpBNKReturnBytes = Des3.decryptMode(p_Key, DES_byte);
//                if (tmpBNKReturnBytes.length == 0) {
//                    this.WriteBankLogLn("3DES解密银行返回的数据失败");
//                    return false;
//                }
//
//                String tmpBNKReturn = new String(tmpBNKReturnBytes, getCharset());
//                boolean enableSalaryDecrypt = getBankConfig().getValueAsBool("enableSalaryDecrypt");
//                if (enableSalaryDecrypt) {
//                    this.WriteBankLogLn("3.银行返回原文信息:\r\n" + FieldHiddenUtil.amountHiddle(tmpBNKReturn, new String[]{"TAmt", "Scss_Amt", "Fail_Amt", "SRP_TxnAmt"}));
//                } else {
//                    this.WriteBankLogLn("3.银行返回原文信息:\r\n" + tmpBNKReturn);
//                }
//                String pubKeys = "";
//                String chanl_cust_no = bankFront.org;
//                pubKeys = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_BnkPubKey.txt", getCharset());
//                //验签
//                if (!RSAHelper.verifySignData(tmpBNKReturn, base64Encoder.encode(Md5_byte), pubKeys, getCharset())) {
//                    this.WriteBankLogLn("验签失败");
//                    throw new Exception("验签失败");
//                }
//
//                //批量，返回FAIL|或者SUCCESS|直接返回
//                if (tmpBNKReturn.contains("FAIL|") || tmpBNKReturn.contains("SUCCESS|") || tmpBNKReturn.contains("FAIL")) {
//                    return true;
//                }
//
//                try {
//                    StringBuilder msg = new StringBuilder();
//                    P_BKRet = loadBankRespXmlReader(tmpBNKReturn, msg);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//                //解析返回报文
//                String xln_status = P_BKRet.getFirstText("/Transaction/Transaction_Header/SYS_TX_STATUS"); // 服务状态
//                String xln_resp_code = P_BKRet.getFirstText("/Transaction/Transaction_Header/SYS_RESP_CODE"); // 服务响应码
//                //String xln_resp_desc = P_BKRet.getFirstText("/Transaction/Transaction_Header/SYS_RESP_DESC"); // 服务响应描述
//
//                if (isLogin) {
//                    String xn_tmpStatus = P_BKRet.getFirstText("/Transaction/Transaction_Header/tran_response/status");
//                    String xn_tmpDesc = P_BKRet.getFirstText("/Transaction/Transaction_Header/tran_response/desc");
//                    if (xln_status != null && xln_status.length() > 0) {
//                        if (xln_status.equals("00") && xn_tmpStatus.equals("COMPLETE")) {
////                            retAtsBase.writeRespCode("0");
////                            retAtsBase.writeRespInfo("success");
//
//                            return true;
//                        } else if (xn_tmpDesc != null && xn_tmpDesc.length() > 0) {
////                        	retAtsBase.writeRespCode("-1");
////                            retAtsBase.writeRespInfo(xn_tmpDesc);
//                            return false;
//                        } else {
////                            retAtsBase.writeRespCode("-1");
////                            retAtsBase.writeRespInfo("");
//                            return false;
//                        }
//                    }
//                }
//                if (xln_status != null && xln_status.length() > 0) {
//                    if (xln_status.equals("00") && xln_resp_code.equals("000000000000"))  //14个0表示成功
//                    {
//                        return true;
//                    }
//                } else {
//                    //retAtsBase.writeRespCode("-1");
//                    //retAtsBase.writeRespInfo("统一接口平台的银行接口（中国建设银行）接收到的银行报文存在异常情况，无SYS_TX_STATUS节点");
//                }
//            } else {
//                //retAtsBase.writeRespCode("-1");
//                //retAtsBase.writeRespInfo("统一接口平台的银行接口（中国建设银行）接收不到银行返回的数据，如要看是否交易成功请查询状态。");
//            }
//        } catch (Exception e) {
//            //retAtsBase.writeRespCode("-1");
//            //retAtsBase.writeRespInfo("解析失败.");
//            this.WriteBankLogLn(e);
//        }
//        return false;
//    }
//
//    protected XmlTextReader getBankInfo(String P_BNKReturn, StringBuilder msg) throws Exception {
//
//        byte[] tmpBNKReturnBytes = null;
//        //XmlTextReader xmlTextReader = null;
//        if (P_BNKReturn.length() > 0 && !"".equals(P_BNKReturn)) {
//            //得到银行返回的数字签名Md5_byte和报文密文DES_byte
//            //HTTP 服务方返回时是返回一个字节流 byte[]，因此需要约定 byte[]的数据格式。
//            //返回的 byte[]的格式：数字签名的长度(固定长度 10 个字节) +数字签名数据+加密后的数据。解密时应先根据前 10 位算出数字签名的长度，然后再截取数字签名及报文密文。
//
//            byte[] data = base64Decoder.decodeBuffer(P_BNKReturn);
//            byte[] len_byte = new byte[10];
//            System.arraycopy(data, 0, len_byte, 0, 10);
//
//            int MD5_len = Integer.valueOf(new String(len_byte));
//            byte[] Md5_byte = new byte[MD5_len];
//            System.arraycopy(data, 10, Md5_byte, 0, MD5_len);
//            byte[] DES_byte = new byte[data.length - 10 - MD5_len];
//            System.arraycopy(data, MD5_len + 10, DES_byte, 0, data.length - 10 - MD5_len);
//
//            //region 3DES字节解密
//
////            byte[] p_Key = triDesKeys;
//            byte[] p_Key = Base64Helper.decode(bankFront.token);
//            tmpBNKReturnBytes = Des3.decryptMode(p_Key, DES_byte);
//            String tmpBNKReturn = new String(tmpBNKReturnBytes, getCharset());
//            boolean enableSalaryDecrypt = getBankConfig().getValueAsBool("enableSalaryDecrypt");
//            if (enableSalaryDecrypt) {
//                this.WriteBankLogLn("3.银行返回原文信息:\r\n" +
//                        FieldHiddenUtil.amountHiddle(tmpBNKReturn, new String[]{"TAmt", "Scss_Amt", "Fail_Amt", "SRP_TxnAmt"}));
//            } else {
//                this.WriteBankLogLn("3.银行返回原文信息:\r\n" + tmpBNKReturn);
//            }
//            return loadBankRespXmlReader(tmpBNKReturn, msg);
//        }
//        return null;
//    }
//
//    //公钥加密  基本类型的形参不会影响实参
//    public List<byte[]> transferRsaKeys() {
//        List<byte[]> list = new ArrayList<byte[]>();
//        byte[] keysReturn = new byte[1024];
//        /*String keysReturn = null;*/
//        try {
//            String chanl_cust_no = bankFront.org;
//            createKeyPair(strtmpFile + chanl_cust_no + "_pubkey.txt", strtmpFile + chanl_cust_no + "_prikey.txt");
//            String publicKey = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_pubkey.txt", getCharset());
//            if (chanl_cust_no.length() > 10) {
//                int len = chanl_cust_no.length();
//                chanl_cust_no = chanl_cust_no.substring(len - 10);
//            } else {
//                chanl_cust_no = decimalFormat.format(chanl_cust_no);
//            }
//            String sKey = chanl_cust_no + Format.Date8Format.format(new Date()).substring(2);//10+yymmdd
//            WriteBankLogLn("解密的skey:" + sKey);
//
//            //byte[] p_OutBytes = new byte[1024];
//            byte[] keys = asc2bin(sKey);
//            list.add("000000".getBytes(getCharset()));
//            keysReturn = DESUtil.desEncrypt(base64Decoder.decodeBuffer(publicKey), keys);
//            WriteBankLogLn("des加密后" + new Date() + "：" + new String(keysReturn));
//            WriteBankLogLn("des加密后数据解密" + new Date() + "：" + base64Encoder.encode(DESUtil.desDecrypt(keysReturn, keys)));
//        } catch (Exception e) {
//            list.add("999999".getBytes());
//            keysReturn = "there is something wrong,please check the error message.".getBytes();
//        }
//        list.add(keysReturn);
//        WriteBankLogLn("des加密后" + new Date() + "：" + new String(keysReturn));
//        return list;
//    }
//
//    //随机生成密钥对
//    public void createKeyPair(String pubkeyfileName, String prikeyfileName) {
//        File pubFile = new File(pubkeyfileName);
//        File privateFile = new File(prikeyfileName);
//        //我们这边的密钥需要银行手动去下载，生成的密钥对文件最好不要随便删
//        if (!pubFile.exists() && !privateFile.exists()) {
//            String chanl_cust_no = bankFront.org;
//            String tmpPubFile = strtmpFile + chanl_cust_no + "_pubkey.txt";
//            String tmpPriFile = strtmpFile + chanl_cust_no + "_prikey.txt";
//
//            //获得对象 KeyPairGenerator 参数 RSA 1024个字节
//            try {
//                KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
//                keyPairGen.initialize(1024);
//                //通过对象 KeyPairGenerator 获取对象KeyPair
//                KeyPair keyPair1 = keyPairGen.generateKeyPair();
//
//                //通过对象 KeyPair 获取RSA公私钥对象RSAPublicKey RSAPrivateKey
//                RSAPublicKey publicKey = (RSAPublicKey) keyPair1.getPublic();
//                RSAPrivateKey privateKey = (RSAPrivateKey) keyPair1.getPrivate();
//                //公私钥对象存入map中
//                Map<String, Object> keyPair = new HashMap<String, Object>(2);
//                keyPair.put("RSAPublicKey", publicKey);
//                keyPair.put("RSAPrivateKey", privateKey);
//                Key pkey = (Key) keyPair.get("RSAPublicKey");
//                String pubkey = new BASE64Encoder().encodeBuffer(pkey.getEncoded());
//                FileHelper.writeFile(tmpPubFile, pubkey, getCharset());
//
//                Key rkey = (Key) keyPair.get("RSAPrivateKey");
//                String prikey = new BASE64Encoder().encodeBuffer(rkey.getEncoded());
//                FileHelper.writeFile(tmpPriFile, prikey, getCharset());
//            } catch (NoSuchAlgorithmException e) {
//                e.fillInStackTrace();
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    }
//
//    public String[] UploadFileByHttpPost(StringBuilder Content) {
//        String[] retStr = new String[]{"", ""};
//        //byte[] tmp1 = new byte[1024];
//        try {
//            WebRequest tmpWebRequest = new WebRequest("http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/UploadFile");
//            WriteBankLogLn("上传地址:http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/UploadFile");
//            tmpWebRequest.setConnectTimeout(60000);
//            tmpWebRequest.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//            tmpWebRequest.setRequestProperty("connection", "Close");
//            tmpWebRequest.setBankFront(bankFront);
//            String charsetName = getCharset();
//            StringBuilder postData = Content;
//            byte[] str_tmpToWriteBytes = postData.toString().getBytes(charsetName);
//            if (isNeedHiddleField) {
//                WriteBankLogLn("发送银行的数据" + postData.toString().substring(0, postData.indexOf("&signature=")) + " ...");
//            } else {
//                WriteBankLogLn("发送银行的数据" + postData.toString());
//            }
//            retStr = tmpWebRequest.upload(str_tmpToWriteBytes, charsetName);
//            WriteBankLogLn("下载银行返回数据" + retStr[1]);
//        } catch (Exception e) {
//            this.WriteBankLogLn("HttpPost文件失败:" + e.getMessage());
//        }
//        return retStr;
//    }
//
//    public String[] downloadFileByHttpPost(StringBuilder Content) {
//        String[] retStr = new String[]{"", ""};
//        //byte[] tmp1 = new byte[1024];
//        try {
//            WebRequest tmpWebRequest = new WebRequest("http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/DownloadFile");
//            WriteBankLogLn("上传地址:http://" + bankFront.serverIP + ":" + bankFront.serverPort + "/interlink/DownloadFile");
//            tmpWebRequest.setConnectTimeout(60000);
//            tmpWebRequest.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//            tmpWebRequest.setRequestProperty("connection", "Close");
//            tmpWebRequest.setBankFront(bankFront);
//            String charsetName = getCharset();
//            StringBuilder postData = Content;
//            byte[] str_tmpToWriteBytes = postData.toString().getBytes(charsetName);
//            if (isNeedHiddleField) {
//                WriteBankLogLn("发送银行的数据" + postData.toString().substring(0, postData.indexOf("&signature=")) + " ...");
//            } else {
//                WriteBankLogLn("发送银行的数据" + postData.toString());
//            }
//            retStr = tmpWebRequest.upload(str_tmpToWriteBytes, charsetName);
//            WriteBankLogLn("下载银行返回数据" + retStr[1]);
//        } catch (Exception e) {
//            this.WriteBankLogLn("HttpPost文件失败:" + e.getMessage());
//        }
//        return retStr;
//    }
//
//    protected String getDownloadFileDate(String P_BNKReturn) throws Exception {
//        //接收到返回结果时，可先按照带数字签名的格式解密，如果解密并验证签名
//        //成功，则表示接收到的是下载失败的错误信息；如果解密或验证失败，表示接收到的是
//        //文件内容
//        WriteBankLogLn("开始检验下载明细文件返回内容");
//        byte[] tmpBNKReturnBytes = null;
//        if (P_BNKReturn.length() > 0 && !"".equals(P_BNKReturn)) {
//            //得到银行返回的数字签名Md5_byte和报文密文DES_byte
//            //HTTP 服务方返回时是返回一个字节流 byte[]，因此需要约定 byte[]的数据格式。
//            //返回的 byte[]的格式：数字签名的长度(固定长度 10 个字节) +数字签名数据+加密后的数据。解密时应先根据前 10 位算出数字签名的长度，然后再截取数字签名及报文密文。
//
//            //银行端返回：
//            //如果文件存在且读取正确，则直接返回对称密钥加密后的文件内容。  如果出现错误，则返回：数字签名长度（10 位）+数字签名+“下载结果|错误代码|错误
//            //信息”
//
//            byte[] data = base64Decoder.decodeBuffer(P_BNKReturn);
//            byte[] len_byte = new byte[10];
//            System.arraycopy(data, 0, len_byte, 0, 10);
//
//            //判断截取的字符是不是数字
//            Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
//            if (pattern.matcher(new String(len_byte)).matches()) {
//                //截取字符是数字
//                int MD5_len = Integer.valueOf(new String(len_byte));
//                WriteBankLogLn("银行返回数字签名长度：" + MD5_len);
//                byte[] Md5_byte = new byte[MD5_len];
//                System.arraycopy(data, 10, Md5_byte, 0, MD5_len);
//                byte[] DES_byte = new byte[data.length - 10 - MD5_len];
//                System.arraycopy(data, MD5_len + 10, DES_byte, 0, data.length - 10 - MD5_len);
//
//                //企业客户端接收到返回结果时，可先按照带数字签名的格式解密，如果解密并验证签名
//                //成功，则表示接收到的是下载失败的错误信息；如果解密或验证失败，表示接收到的是
//                //文件内容。
//
//                try {
//                    //region 3DES字节解密
//                    byte[] p_Key = Base64Helper.decode(bankFront.token);
//                    tmpBNKReturnBytes = Des3.decryptMode(p_Key, DES_byte);
//                    String tmpBNKReturn = new String(tmpBNKReturnBytes, getCharset());
//                    //this.WriteBankLogLn("3.银行返回原文信息:\r\n" + tmpBNKReturn);
//                    String pubKeys = "";
//                    String chanl_cust_no = bankFront.org;
//                    pubKeys = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_BnkPubKey.txt", getCharset());
//                    //验签
//                    if (!RSAHelper.verifySignData(tmpBNKReturn, base64Encoder.encode(Md5_byte), pubKeys, getCharset())) {
//                        this.WriteBankLogLn("验签失败");
//                        throw new Exception("验签失败");
//                    }
//
//                    //文件下载失败
//                    if (tmpBNKReturn.contains("FAIL|")) {
//                        this.WriteBankLogLn("明细文件下载失败：" + tmpBNKReturn);
//                        return tmpBNKReturn;
//                    }
//                } catch (Exception e) {
//                    //解密出错则为文件内容
//                    this.WriteBankLogLn("开始文件内容解密解析");
//                    //region 3DES字节解密
//                    byte[] p_Key = Base64Helper.decode(bankFront.token);
//                    tmpBNKReturnBytes = Des3.decryptMode(p_Key, data);
//                    String tmpBNKReturn = new String(tmpBNKReturnBytes, "GBK");
//                    WriteBankLogLn("下载的明细文件内容：" + tmpBNKReturn);
//                    return tmpBNKReturn;
//                }
//            } else {
//                this.WriteBankLogLn("开始文件内容解密解析");
//                //region 3DES字节解密
//                byte[] p_Key = Base64Helper.decode(bankFront.token);
//                tmpBNKReturnBytes = Des3.decryptMode(p_Key, data);
//                String tmpBNKReturn = new String(tmpBNKReturnBytes, "GBK");
//                WriteBankLogLn("下载的明细文件内容：" + tmpBNKReturn);
//                return tmpBNKReturn;
//            }
//        }
//        return "";
//    }
//
//    protected String IsBatchValid(String P_BNKReturn) throws Exception {
//        WriteBankLogLn("开始检验HTTPPOST返回内容");
//        byte[] tmpBNKReturnBytes = null;
//        if (P_BNKReturn.length() > 0 && !"".equals(P_BNKReturn)) {
//            //得到银行返回的数字签名Md5_byte和报文密文DES_byte
//            //HTTP 服务方返回时是返回一个字节流 byte[]，因此需要约定 byte[]的数据格式。
//            //返回的 byte[]的格式：数字签名的长度(固定长度 10 个字节) +数字签名数据+加密后的数据。解密时应先根据前 10 位算出数字签名的长度，然后再截取数字签名及报文密文。
//
//            byte[] data = base64Decoder.decodeBuffer(P_BNKReturn);
//            byte[] len_byte = new byte[10];
//            System.arraycopy(data, 0, len_byte, 0, 10);
//
//            int MD5_len = Integer.valueOf(new String(len_byte));
//            byte[] Md5_byte = new byte[MD5_len];
//            System.arraycopy(data, 10, Md5_byte, 0, MD5_len);
//            byte[] DES_byte = new byte[data.length - 10 - MD5_len];
//            System.arraycopy(data, MD5_len + 10, DES_byte, 0, data.length - 10 - MD5_len);
//
//            //region 3DES字节解密
//
////            byte[] p_Key = triDesKeys;
//            byte[] p_Key = Base64Helper.decode(bankFront.token);
//            tmpBNKReturnBytes = Des3.decryptMode(p_Key, DES_byte);
//
//            String tmpBNKReturn = new String(tmpBNKReturnBytes, getCharset());
//            //this.WriteBankLogLn("3.银行返回原文信息:\r\n" + tmpBNKReturn);
//            String pubKeys = "";
//            String chanl_cust_no = bankFront.org;
//            pubKeys = FileHelper.readFileText(strtmpFile + chanl_cust_no + "_BnkPubKey.txt", getCharset());
//            //验签
//            if (!RSAHelper.verifySignData(tmpBNKReturn, base64Encoder.encode(Md5_byte), pubKeys, getCharset())) {
//                this.WriteBankLogLn("验签失败");
//                throw new Exception("验签失败");
//            }
//
//            //批量，返回FAIL|或者SUCCESS|直接返回
//            if (tmpBNKReturn.contains("FAIL|") || tmpBNKReturn.contains("SUCCESS|")) {
//                WriteBankLogLn("返回批量内容：" + tmpBNKReturn);
//                return tmpBNKReturn;
//            }
//
//        }
//        return "";
//    }
//
//    //上送格式为json格式
//    protected String[] sendToATS(String jsonData) throws Exception {
//        String[] retStr = new String[]{"", ""};
//        WriteBankLogLn("2.提交ATS的地址：" + FGBiz.dspCenter.dspSet.receiptPushServerUrl);
//
//        //发送银行前置
//        WebRequest tmpRequest = new WebRequest(FGBiz.dspCenter.dspSet.receiptPushServerUrl);
//        tmpRequest.setConnectTimeout(10000);
//        tmpRequest.setRequestProperty("connection", "Close");
//        tmpRequest.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//        String charsetName = getCharset();
//        StringBuilder data = new StringBuilder();
//        data.append(jsonData);
//        WriteBankLogLn("3.推送给ATS的数据" + data.toString());
//        byte[] tmpWriteBytes = data.toString().getBytes(charsetName);
//        retStr = tmpRequest.upload(tmpWriteBytes, charsetName);
//        WriteBankLogLn("4.返回的数据" + retStr[1]);
//
//        return retStr;
//    }
//
//    //因为银行返回的明细文件内容换行是"\n"结尾,行与行之间没有使用列的分隔符 使用MFSHelper.retrieveMFSData(...) 每行最后一个数据会少一个字符
//    protected List<List<String>> retrieveMFSData(String text, int expectedFieldNum, int expectedRecordNum, StringBuilder p_sbLog) {
//        List<List<String>> result = new ArrayList();
//        String[] record = text.split("\\n");
//        for (int i = 0; i < record.length; i++) {
//            result.add(Arrays.asList(record[i].split("\\|", -1)));
//            if (result.get(result.size() - 1).size() != expectedFieldNum) {
//                p_sbLog.append("MFS数据列数预期为" + expectedFieldNum + "，但是实际为" + result.get(result.size() - 1).size());
//                result.clear();
//                break;
//            }
//        }
//        if (result.size() != expectedRecordNum) {
//            p_sbLog.append("MFS数据行数预期为" + expectedRecordNum + "，但是实际为" + result.size());
//            result.clear();
//        }
//        return result;
//    }
//
//    /**
//     * 票据背面信息查询业务转换
//     * 交易类型代码 2  承兑 3  收票 4  撤票 10  背书转让 11  贴现 12  回购式贴现赎回 13  转贴现 14  回购式转贴现赎回 15  再贴现
//     * 16  回购式再贴现赎回 25  央行卖出商业汇票 17  保证 18  质押 19  质押解除 20  提示付款 21  逾期提示付款 22  追索 23  追索同意清偿
//     *
//     * @return
//     */
//    protected String getTransCode(String billType) {
//        String transCode = "";
//        if (!StringHelper.isNullOrEmpty(billType)) {
//            switch (Integer.parseInt(billType)) {
//                case 0:
//                    transCode = "10";
//                    break;//背书
//                case 1:
//                    transCode = "17";
//                    break;//保证
//                case 2:
//                    transCode = "18";
//                    break;//18  质押
//                case 3:
//                    transCode = "11";
//                    break;//买断式贴现
//                case 4:
//                    transCode = "11";
//                    break;//回购式贴现
//                case 5:
//                    transCode = "12";
//                    break;//回购式贴现赎回
//                case 6:
//                    transCode = "13";
//                    break;//买断式转贴现
//                case 7:
//                    transCode = "13";
//                    break;//回购式转贴现
//                case 8:
//                    transCode = "14";
//                    break;//14  回购式转贴现赎回
//                case 9:
//                    transCode = "15";
//                    break;//买断式再贴现
//                case 10:
//                    transCode = "15";
//                    break;//回购式再贴现
//                case 11:
//                    transCode = "16";
//                    break;//16  回购式再贴现赎回
//                case 12:
//                    transCode = "25";
//                    break;//25  央行卖出商业汇票
//                case 13:
//                    transCode = "20";
//                    break;//提示付款
//                //case 13:transCode="21";break;//逾期提示付款
//                case 14:
//                    transCode = "22";
//                    break;//追索
//                case 15:
//                    transCode = "22";
//                    break;//再追索
//                //case 020006:transCode="23";break;//追索同意清偿
//                default:
//                    transCode = "";
//            }
//        }
//        return transCode;
//    }
//
//    protected boolean comprareTime(String date,String date1) throws Exception {
//        boolean flag = false;
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        Date startDate = sdf.parse(date);
//        Date sysDate = sdf.parse(DateHelper.convertD8toD10(date1));
//        if(startDate!=null){
//            long useTime = startDate.getTime();
//            long sysTime = sysDate.getTime();
//            if(sysTime>useTime){
//                flag = true;
//            }
//        }
//        return flag;
//    }
//}
